RUNNER = dep/run/runner.js
TESTS = tests/*.js
HTMLTESTS = tests/*.html
RESULTS = results
PERF = perf
WEB = web
PERFSINGLE = perf-single

all: clean web

web: ${TESTS}
	@@ rm -rf ${WEB}
	@@ cp -fR dep/web ${WEB}
	@@ mkdir ${WEB}/tests
	@@ cp -f tests/MANIFEST.json ${WEB}/tests/MANIFEST.json
	@@ for i in ${TESTS}; do \
		echo "Converting $${i} to web test..."; \
		cat dep/web/test-head.html "$${i}" dep/web/test-tail.html | \
			sed "s/startTest.\(.*\).;/startTest\(\1, '`crc32 $${i}`'\);/" | \
			sed "s/startTest/window.onload = function(){ startTest/" | \
			sed "s/endTest..;/endTest(); };/" > \
			${WEB}/`echo "$${i}"|sed s/.js//`.html; \
	done

perf: ${TESTS}
	@@ mkdir -p ${PERF}
	@@ cp -f ${RUNNER} ${PERF}/
	@@ for i in ${TESTS}; do \
		echo "Converting $${i} to perf test..."; \
		cat dep/perf/head.html "$${i}" dep/perf/tail.html > \
			${PERF}/`echo "$${i}"|sed s/.js//|sed s/tests.//`.html; \
	done

perf-single: ${TESTS}
	@@ mkdir -p ${PERFSINGLE}
	@@ cp -f ${RUNNER} ${PERFSINGLE}/
	@@ echo "Generating single perf tests..."
	@@ perl dep/perf/single.pl ${RESULTS}/spidermonkey.txt

clean:
	@@ rm -rf ${PERF}
	@@ rm -rf ${PERFSINGLE}
	@@ rm -rf ${RESULTS}
	@@ rm -rf ${WEB}
